package cn.monkey.family.data.shop.item.type;

import cn.monkey.family.data.DataMapper;
import cn.monkey.family.data.TreeMapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.Collection;

@Mapper(unmappedTargetPolicy = org.mapstruct.ReportingPolicy.IGNORE)
public interface ItemTypeMapper extends DataMapper<ItemTypeDto, ItemType, ItemTypeVo>, TreeMapper<String, ItemType, ItemTypeVo> {
    @Override
    @Mapping(target = "module", constant = ItemType.MODULE)
    ItemType toEntity(ItemTypeDto itemTypeDto);

    @Override
    ItemTypeVo toVo(ItemType itemType);

    default Collection<ItemTypeVo> toTree(Collection<ItemType> types, Integer maxDeep) {
        return TreeMapper.super.toTree(types, this::toVo, ItemType::getKey, ItemType::getParentKey, ItemTypeVo::setChild, maxDeep == null ? 0 : maxDeep);
    }
}
